# coding=utf-8
from datetime import timedelta
from redis import Redis

Debug = True
UserKey = "user"

is_exist = "exist"

SQLALCHEMY_ENCODING = 'utf8mb4'


# 前缀
class Prefixs(object):
    userID_prefix = "user_"
    user_token_prefix = "tokenID:"
    login_captcha_prefix = "login:captcha:"
    blog_liked_prefix = "blog:liked:"
    shop_cache_prefix = "cache:shop:"
    lock_shop_key = "lock:shop:"
    lock_shoptype_list = "lock:shop-type:list"
    voucher_create_prefix = "voucher_count:"
    incr_voucher_orderId_prefix = "incr:voucher:orderid:"  # redis存储的自增长优惠券订单id
    voucherIdPrefix_with_userIdSet = 'set:voucherId:'  # 对应id的优惠券作为set的key，存储对应优惠券中已经下单的用户id
    lock_voucher_order_prefix = "lock:voucher:order:"  # + userid
    seckill_voucher_stock_prefix = "skvoucher:stock:"  # + id 缓存到秒杀券库存key的前缀
    userSet_of_blog_prefix = "blog:liked:"  # + blogID,集合结构存储用户id，实现点赞功能
    follow_user_set_prefix = "follow:userid:"
    feed_prefix = 'feed:'  # + userId 用户收信箱
    shop_geo = 'shop:geo:'  # + typeid 通过商店类型分类存储地理位置
    user_sign_key = "sign:"

# redis stream 消费者组配置
stream_name = "stream.order"
groupname = "g1"
consumername_profix = 'machine:1:'

# session配置
SESSION_USE_SIGNER = True
SECRET_KEY = "ahgnmhgmjmasss"
PERMANENT_SESSION_LIFETIME = timedelta(days=1)  # PERMANENT = True 时的过期时间
SESSION_TYPE = "redis"
SESSION_REDIS = Redis(host='127.0.0.1', port='6379')
# mysql配置
HOSTNAME = '127.0.0.1'
POST = 3306
USERNAME = 'root'
PASSWARD = '2624268757'
DATABASE = 'hmdp'
DB_URI = f'mysql+pymysql://{USERNAME}:{PASSWARD}@{HOSTNAME}:{POST}/{DATABASE}?charset=utf8mb4'
SQLALCHEMY_DATABASE_URI = DB_URI
SQLALCHEMY_TRACK_MODIFICATIONS = False  # 自动提交，对性能有影响，而容易产生冲突

# redis配置
REDIS_HOST = "127.0.0.1"  # redis数据库地址
REDIS_PORT = 6379  # redis 端口号
REDIS_DB = 0  # 数据库名
REDIS_EXPIRE = 60  # redis 过期时间60秒

# flask-caching配置
flask_caching_config = {
    "CACHE_DEFAULT_TIMEOUT": 60,
    "CACHE_TYPE": 'redis',
    "REDIS_HOST": '127.0.0.1',
    "REDIS_PORT": 6379,
    "REDIS_PASSWORD": None,
    "REDIS_DB": 0
}
